<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::Notifications::Fanout</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveSupport::Notifications::Fanout 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activesupport/lib/active_support/notifications/fanout_rb.html">activesupport/lib/active_support/notifications/fanout.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>This is a default queue implementation that ships with <a
href="../Notifications.html">Notifications</a>. It just pushes events to
all registered log subscribers.</p>

<p>This class is thread safe. All methods are reentrant.</p>

    </div>
  


  


  
  


  
    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
      
        <li>
          <span class="type">MODULE</span>
          <a href="Fanout/Subscribers.html">ActiveSupport::Notifications::Fanout::Subscribers</a>
        </li>
      
    </ul>
  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-i-finish">finish</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-i-listeners_for">listeners_for</a>,
              </li>
            
              
              <li>
                <a href="Fanout.html#method-i-listening-3F">listening?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-i-publish">publish</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-i-start">start</a>,
              </li>
            
              
              <li>
                <a href="Fanout.html#method-i-subscribe">subscribe</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-i-unsubscribe">unsubscribe</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>W</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Fanout.html#method-i-wait">wait</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            Mutex_m
          
        </li>
      
    </ul>
  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>()
            
            <a href="Fanout.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L13" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 13</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>
  <span class="ruby-ivar">@subscribers</span> = []
  <span class="ruby-ivar">@listeners_for</span> = <span class="ruby-constant">ThreadSafe</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-finish">
            
              <b>finish</b>(name, id, payload)
            
            <a href="Fanout.html#method-i-finish" name="method-i-finish" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-finish_source')" id="l_method-i-finish_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L39" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-finish_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 39</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">finish</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">payload</span>)
  <span class="ruby-identifier">listeners_for</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">finish</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">payload</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-listeners_for">
            
              <b>listeners_for</b>(name)
            
            <a href="Fanout.html#method-i-listeners_for" name="method-i-listeners_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-listeners_for_source')" id="l_method-i-listeners_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L47" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-listeners_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 47</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">listeners_for</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-comment"># this is correctly done double-checked locking (ThreadSafe::Cache's lookups have volatile semantics)</span>
  <span class="ruby-ivar">@listeners_for</span>[<span class="ruby-identifier">name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-comment"># use synchronisation when accessing @subscribers</span>
    <span class="ruby-ivar">@listeners_for</span>[<span class="ruby-identifier">name</span>] <span class="ruby-operator">||=</span> <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">subscribed_to?</span>(<span class="ruby-identifier">name</span>) }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-listening-3F">
            
              <b>listening?</b>(name)
            
            <a href="Fanout.html#method-i-listening-3F" name="method-i-listening-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-listening-3F_source')" id="l_method-i-listening-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L55" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-listening-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">listening?</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-identifier">listeners_for</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">any?</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-publish">
            
              <b>publish</b>(name, *args)
            
            <a href="Fanout.html#method-i-publish" name="method-i-publish" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-publish_source')" id="l_method-i-publish_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L43" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-publish_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 43</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">publish</span>(<span class="ruby-identifier">name</span>, *<span class="ruby-identifier">args</span>)
  <span class="ruby-identifier">listeners_for</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">publish</span>(<span class="ruby-identifier">name</span>, *<span class="ruby-identifier">args</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-start">
            
              <b>start</b>(name, id, payload)
            
            <a href="Fanout.html#method-i-start" name="method-i-start" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-start_source')" id="l_method-i-start_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L35" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-start_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">payload</span>)
  <span class="ruby-identifier">listeners_for</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">payload</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-subscribe">
            
              <b>subscribe</b>(pattern = nil, block = Proc.new)
            
            <a href="Fanout.html#method-i-subscribe" name="method-i-subscribe" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-subscribe_source')" id="l_method-i-subscribe_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L19" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-subscribe_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">subscribe</span>(<span class="ruby-identifier">pattern</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">block</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span>)
  <span class="ruby-identifier">subscriber</span> = <span class="ruby-constant">Subscribers</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">pattern</span>, <span class="ruby-identifier">block</span>
  <span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-ivar">@subscribers</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">subscriber</span>
    <span class="ruby-ivar">@listeners_for</span>.<span class="ruby-identifier">clear</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">subscriber</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-unsubscribe">
            
              <b>unsubscribe</b>(subscriber)
            
            <a href="Fanout.html#method-i-unsubscribe" name="method-i-unsubscribe" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-unsubscribe_source')" id="l_method-i-unsubscribe_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L28" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-unsubscribe_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 28</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">unsubscribe</span>(<span class="ruby-identifier">subscriber</span>)
  <span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-ivar">@subscribers</span>.<span class="ruby-identifier">reject!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">matches?</span>(<span class="ruby-identifier">subscriber</span>) }
    <span class="ruby-ivar">@listeners_for</span>.<span class="ruby-identifier">clear</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-wait">
            
              <b>wait</b>()
            
            <a href="Fanout.html#method-i-wait" name="method-i-wait" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>This is a sync queue, so there is no waiting.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-wait_source')" id="l_method-i-wait_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2a7229348eeca21a2b2e2669aa31beafdc9cc64d/activesupport/lib/active_support/notifications/fanout.rb#L60" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-wait_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/fanout.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">wait</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    